#include "cesium/sinkset.hpp"

namespace Cesium {

SinkSet::SinkSet() {
}

SinkSet::~SinkSet() {
    for(std::set<Stage*>::iterator it = sinks.begin(); it != sinks.end(); it++)
        (*it)->unref();
}

void SinkSet::add(Stage* sink) {
    sink->ref();
    sinks.insert(sink);
}

void SinkSet::remove(Stage* sink) {
    uint32 count = sinks.erase(sink);
    for(uint32 i = 0; i < count; i++)
        sink->unref();
}

void SinkSet::signal(Stage* src, Buffer* data) {
    BufferRange range(0, data->size());
    signal(src, data, range);
}

void SinkSet::signal(Stage* src, Buffer* data, BufferRange range) {
    for(std::set<Stage*>::iterator it = sinks.begin(); it != sinks.end(); it++)
        (*it)->signal(src, data, range);
}

} // namespace Cesium
